#ifndef __FSL_IOCTL_H__
#define __FSL_IOCTL_H__
#ifdef __cpluscplus
extern "C" {
#endif

#include <stdint.h>
#include "list.h"

#define FSL_IOCTL_LOOP_GAP_TICK    0
#define FSL_IOCTL_LOOP_SYS_TICK    1
#define FSL_IOCTL_LOOP_CALL_MODE   FSL_IOCTL_LOOP_GAP_TICK

typedef struct {
    uint8_t state;
    uint8_t repeat_cnt;
    uint8_t repeat_cfg;
    uint16_t on_time_cfg;
    uint16_t off_time_cfg;
    uint32_t start_tick;
    void (*on)(void);
    void (*off)(void);
    list_obj_t list;
} ioctl_dev_t;

void fsl_ioctl_init_dev(ioctl_dev_t *dev);
void fsl_ioctl_register_dev(ioctl_dev_t *dev);

#if FSL_IOCTL_LOOP_CALL_MODE == FSL_IOCTL_LOOP_GAP_TICK
void fsl_ioctl_loop(uint8_t loop_gap_ms);
#elif FSL_IOCTL_LOOP_CALL_MODE == FSL_IOCTL_LOOP_SYS_TICK
void fsl_ioctl_loop(uint32_t system_tick_ms);
#endif

void fsl_ioctl_setup(ioctl_dev_t *dev, uint16_t on_time_ms, uint16_t off_time_ms, uint8_t repeat_num);
uint8_t fsl_ioctl_is_busy(ioctl_dev_t *dev);

#define IOCTL_HOLD      0xFF

#ifdef __cpluscplus
}
#endif
#endif
